package com.iotsz.common.utils;

import org.apache.http.HttpStatus;

import java.util.HashMap;
import java.util.Map;

public class IOTResp extends HashMap<String, Object> {
    private static final long serialVersionUID = 1L;

    public IOTResp() {
        put("code", 0);
        put("msg", "success");
    }

    public static IOTResp success(String msg) {
        IOTResp iotResp = new IOTResp();
        iotResp.put("msg", msg);
        return iotResp;
    }

    public static IOTResp success(Map<String, Object> map) {
        IOTResp iotResp = new IOTResp();
        iotResp.putAll(map);
        return iotResp;
    }

    public static IOTResp success() {
        return new IOTResp();
    }

    public IOTResp put(String key, Object value) {
        super.put(key, value);
        return this;
    }

    public static IOTResp error() {
        return error(HttpStatus.SC_INTERNAL_SERVER_ERROR, "未知异常，QAQ");
    }

    public static IOTResp error(String msg) {
        return error(HttpStatus.SC_INTERNAL_SERVER_ERROR, msg);
    }

    public static IOTResp error(int code, String msg) {
        IOTResp iotResp = new IOTResp();
        iotResp.put("code", code);
        iotResp.put("msg", msg);
        return iotResp;
    }
}
